import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

import pyglet
from pyglet.gl import *

from cocos.director import *
from cocos.menu import *
from cocos.scene import *
from cocos.layer import *
from cocos.actions import *
from cocos.sprite import Sprite
from cocos.text import *

from cocos import tiles, actions, layer

GAME_NAME = "ProgrammedMe - Warrior"

class StartGame(Scene):
	def __init__(self):
		super(StartGame, self).__init__()




		scroller = ScrollingManager()
		scrollable = tiles.load_tmx('zigzag.tmx')['one']
		scroller.add(scrollable)
		self.add(scroller)

		label = Label('Welcome to the isometric pixel-art world!',
		font_name='Times New Roman',
		font_size=24,
		anchor_x='center', anchor_y='center')
		label.position = 320,240
		#self.add( label )

class MainMenu(Menu):
    def __init__( self ):
		super( MainMenu, self ).__init__(GAME_NAME)

		pyglet.font.add_directory('.')

		# you can override the font that will be used for the title and the items
		self.font_title['font_name'] = 'You Are Loved'
		self.font_title['font_size'] = 36

		self.font_item['font_name'] = 'You Are Loved'
		self.font_item['font_size'] = 24
		self.font_item_selected['font_name'] = 'You Are Loved'
		self.font_item_selected['font_size'] = 30

		# you can also override the font size and the colors. see menu.py for
		# more info

		# example: menus can be vertical aligned and horizontal aligned
		self.menu_valign = CENTER
		self.menu_halign = CENTER

		items = []

		items.append( MenuItem('New Game', self.on_new_game ) )
		items.append( MenuItem('Options', self.on_options ) )
		items.append( MenuItem('Scores', self.on_scores ) )
		items.append( MenuItem('Quit', self.on_quit ) )

		self.create_menu( items, zoom_in(), zoom_out() )

    # Callbacks
    def on_new_game( self ):
        director.run( StartGame() )

    def on_scores( self ):
        self.parent.switch_to( 2 )

    def on_options( self ):
        self.parent.switch_to( 1 )

    def on_quit( self ):
        director.pop()

class OptionMenu(Menu):
    def __init__( self ):
		super( OptionMenu, self ).__init__(GAME_NAME)

		self.font_title['font_name'] = 'You Are Loved'
		self.font_title['font_size'] = 36

		self.font_item['font_name'] = 'You Are Loved'
		self.font_item['font_size'] = 24
		self.font_item_selected['font_name'] = 'You Are Loved'
		self.font_item_selected['font_size'] = 30

		self.menu_valign = BOTTOM
		self.menu_halign = RIGHT

		items = []
		items.append( MenuItem('Fullscreen', self.on_fullscreen) )
		items.append( ToggleMenuItem('Show FPS: ', self.on_show_fps, True) )
		items.append( MenuItem('OK', self.on_quit) )
		self.create_menu( items, shake(), shake_back() )

    # Callbacks
    def on_fullscreen( self ):
        director.window.set_fullscreen( not director.window.fullscreen )

    def on_quit( self ):
        self.parent.switch_to( 0 )

    def on_show_fps( self, value ):
        director.show_FPS = value

def init():
    director.init( resizable=True, width=640, height=480)

def start():
	director.set_depth_test()
	menulayer = MultiplexLayer(MainMenu(), OptionMenu())
	scene =Scene(menulayer)
	return scene


def run(scene):
    director.run( scene )

if __name__ == "__main__":
    init()
    s = start()
    run(s)
